<!DOCTYPE html>
<html>
<head>
	<title>支付</title>
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<link type="text/css" rel="stylesheet" href="../css/bootstrap.css">
	<link type="text/css" rel="stylesheet" href="../css/style.css">
	<script type="text/javascript" src="../js/jquery-3.1.1.min.js"></script>
	<script type="text/javascript" src="../js/bootstrap.min.js"></script>
	<script type="text/javascript" src="../layer/layer.js"></script>
	<script type="text/javascript" src="../js/cart.js"></script>
	<script type="text/javascript" src="../js/CookieShop.js"></script>
</head>
<body>
	<!--header-->
	<div class="header">
        <div class="container">
            <nav class="navbar navbar-default" role="navigation">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <h1 class="navbar-brand"><a href="./index"></a></h1>
                </div>
                <!--navbar-header-->
                <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                    <ul class="nav navbar-nav">
                        <li><a href="./index.html">首页</a></li>
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">商品分类<b class="caret"></b></a>
                            <ul class="dropdown-menu multi-column columns-2">
                                <li>
                                    <div class="row">
                                        <div class="col-sm-12">
                                            <h4>商品分类</h4>
                                            <ul class="multi-column-dropdown" id="goodsTypeMenu">
                                                <li><a class="list" href="./goods_list.html">全部系列</a></li>
                                            </ul>
                                        </div>
                                    </div>
                                </li>
                            </ul>
                        </li>
                        <li><a href="./goodsrecommend_list.html?recommendTypeId=2">热销</a></li>
                        <li><a href="./goodsrecommend_list.html?recommendTypeId=3">新品</a></li>


                    </ul>
                    <!--/.navbar-collapse-->
                </div>
                <!--//navbar-header-->
            </nav>
            <div class="header-info">
                <div class="header-right search-box">
                    <a href="javascript:;"><span class="glyphicon glyphicon-search" aria-hidden="true"></span></a>
                    <div class="search">
                        <form class="navbar-form" action="./goods_search.html">
                            <input type="text" class="form-control" name="keyword">
                            <button type="submit" class="btn btn-default" aria-label="Left Align">搜索</button>
                        </form>
                    </div>
                </div>

                <div class="header-right cart">
                    <a href="./goods_cart.html">
                        <span class="glyphicon glyphicon-shopping-cart active" aria-hidden="true"><span class="card_num"></span></span>
                    </a>
                </div>
                <div class="clearfix"> </div>
            </div>
            <div class="clearfix"> </div>
        </div>
    </div>
	<!--//header-->
	<div class="cart-items">
		<div class="container">
			<h2>确认收货信息</h2>
			<form class="form-horizontal" action="" method="post" id="payform">
				<div class="row">
					<label class="control-label col-md-1">收货人</label>
					<div class="col-md-6">
						<input type="text" class="form-control" name="name" id="userName" style="height:auto;padding:10px;" placeholder="输入收货人" required="required"><br>
					</div>
				</div>
				<div class="row">
					<label class="control-label col-md-1">收货电话</label>
					<div class="col-md-6">
						<input type="text" class="form-control" name="phone" id="phone" style="height:auto;padding:10px;" placeholder="输入收货电话" required="required"><br>
					</div>
				</div>
				<div class="row">
					<label class="control-label col-md-1">收货地址</label>
					<div class="col-md-6">
						<input type="text" class="form-control" name="address" id="address" style="height:auto;padding:10px;" placeholder="输入收货地址" required="required"><br>
					</div>
				</div>

				<br><hr><br>

				<h2>选择支付方式</h2>
				<input type="hidden" id="totalHidden"></input>
				<h3>支付金额: <span id="total"></span></h3><br><br>


				<div class="col-sm-6 col-md-4 col-lg-3 " >
					<label>
						<div class="thumbnail">
							<input type="radio" name="paytype" value="1" checked="checked" />
							<img src="../images/wechat.jpg" alt="微信支付">
						</div>
					</label>
				</div>
				<div class="col-sm-6 col-md-4 col-lg-3 " >
					<label>
						<div class="thumbnail">
							<input type="radio" name="paytype" value="2"  />
							<img src="../images/alipay.jpg" alt="支付宝支付">
						</div>
					</label>
				</div>
				<div class="clearfix"> </div>
				<div class="register-but text-center">
					<input type="submit" value="确认订单" onclick="custOrderConfirm()">
					<div class="clearfix"> </div>
				</div>
			</form>
		</div>
	</div>
	<!--footer-->
	<div class="footer">
        <div class="container">
            <div class="text-center">

            </div>
        </div>
    </div>
	<!--//footer-->
</body>
<script type="text/javascript">
$(document).ready(function(){
  countMyCart();
  genGoodsTypesMenu();
  loadData();
});

function loadData(){
	$.ajax({
		type:"post",
		url: "../../custcontroller/goodsCustController/cust_order_data_comfirm",
		dataType: 'json',
		success: function(data, textStatus) {
			debugger;
			if ( data.success == true ){
			    $("#userName").val(data.user.userName);
				$("#phone").val(data.user.phone);
				$("#address").val(data.user.address);
				$("#totalHidden").val(data.total);
				$("#total").text(data.total);
			}
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}


function custOrderConfirm(){
    $.ajax({
		type:"post",
		url: "../custcontroller/goodsCustController/cust_order_confirm",
		data: JSON.stringify({
		    userName:$("#userName").val(),
			phone:$("#phone").val(),
			address:$("#address").val(),
			total:parseFloat($("#totalHidden").val()),
			payTypeId:parseInt($("input[name='paytype']:checked").val()),
		}),
		dataType: 'json',
		contentType:"application/json;charset=UTF-8",
		success: function(data, textStatus) {
			debugger;
			if(data.success == true)
			{
			 layer.msg(data.message, {time:3000}, function(){
              });
			 window.location.href="./order_success.html?message="+data.message;
			}
			else if(data.success == false)
			{
            layer.msg(data.error, {time:800}, function(){

            });
			}
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}
</script>
</html>
